-
Notifications
You must be signed in to change notification settings - Fork 61
idtools: avoid direct use of C.stderr to fix musl cgo build failures #559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
✅ A new PR has been created in buildah to vendor these changes: containers/buildah#6606 |
Honny1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM
mtrmac
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Code LGTM.
Could you add at least some summary of the (great) description in the commit message also as a comment directly to the subid_stderr function, please? I’m worried that in a few years, someone (like me) might “simplify” this code without carefully studying the commit history to understand the rationale.
On musl-based systems, stderr is declared as FILE *const. Referencing stderr directly from Go code (via C.stderr) causes cgo to generate assignment code for a const-qualified pointer, which is invalid C and fails to compile. Both gcc and clang reject the generated code with error messages below: clang: > cgo-gcc-prolog:85:9: error: cannot assign to variable '_cgo_r' with const-qualified type 'typeof (_cgo_a->r)' (aka 'struct _IO_FILE *const') > cgo-gcc-prolog:83:24: note: variable '_cgo_r' declared const here > cgo-gcc-prolog:88:12: error: cannot assign to non-static data member 'r' with const-qualified type 'FILE *const' (aka 'struct _IO_FILE *const') > cgo-gcc-prolog:80:15: note: non-static data member 'r' declared const here gcc: > cgo-gcc-prolog:85:9: error: assignment of read-only variable '_cgo_r' > cgo-gcc-prolog:88:12: error: assignment of read-only member 'r' This patch avoids referencing C.stderr from Go code and instead returns stderr from a small C helper function. This keeps the usage entirely in C and avoids cgo’s broken handling for const-qualified global objects. Signed-off-by: Z. Liu <zhixu.liu@gmail.com>
mtrmac
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again!
|
the problem had been fixed by go side (in 1.26 branch) too, see commit https://go.googlesource.com/go/+/7a6e3f07acfd822aa1d62f1c715125e30d67d089%5E%21/ |
On musl-based systems, stderr is declared as FILE *const.
Referencing stderr directly from Go code (via C.stderr) causes cgo to generate assignment code for a const-qualified pointer, which is invalid C and fails to compile.
Both gcc and clang reject the generated code with error messages below:
clang:
gcc:
This patch avoids referencing C.stderr from Go code and instead returns stderr from a small C helper function. This keeps the usage entirely in C and avoids cgo’s broken handling for const-qualified global objects.